package uk.ac.aber.paws.client.idlelogger.events;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Hashtable;

import uk.ac.aber.paws.client.config.ConfigManager;
import uk.ac.aber.paws.client.idlelogger.IdleLogger;
import uk.ac.aber.paws.client.idlelogger.gui.PAWSSysTray;
import uk.ac.aber.paws.client.net.SendMessage;

/**
 * @author Rob Johnson, Aberystwyth University
 * @email rob.johnson@aber.ac.uk
 * @date 8th August 2011
 * 
 * SysTrayListener.java
 * 
 * Listener for the PAWS Idle Logger sys tray icon
 *    
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
public class SysTrayListener implements MouseListener {  

	@Override
	public void mouseClicked(MouseEvent arg0) {
		
		// if the left mouse button is clicked on the PAWS SysTray icon
		if (arg0.getButton() == MouseEvent.BUTTON1) {
			
			// if not in error mode - request and display information
			if (!IdleLogger.getErrorMode()) {
				
	    		Hashtable<String,Object> info = SendMessage.requestInformation(Integer.parseInt(IdleLogger.getMainConfig().getProperty("app.main.net.secureservercommsport")));		
	    		
	    		if (info != null) {
	    			IdleLogger.setInfo(info);
	    			
	    			// check that the PAWS Client hasn't been updated
	    			
	    		}
	    		PAWSSysTray.displayWindow("NORMAL");
	    	}
			// if in error mode, display warning mode
	    	else {
	    		PAWSSysTray.displayWindow("WARNING");
	    	}
		}
	}

	@Override
	public void mouseEntered(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseReleased(MouseEvent arg0) {
		// TODO Auto-generated method stub
		
	}
}
